import java.sql.*;

public class WorldSql2 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        String jdbcUrl="jdbc:mysql://localhost:3308/world";
        String user="root";
        String password="";
        try(Connection conn = DriverManager.getConnection(jdbcUrl, user, password);
            Statement statement = conn.createStatement()) {
            ResultSet result =
                    statement.executeQuery("SELECT Population FROM country WHERE Region=\"Middle East\" ");
            System.out.println("世界上的所有中东国家的总人口:");
            int sum=0;
            while (result.next()){
                sum+=result.getInt(1);
            }
            System.out.println(sum);
        } catch(SQLException ex) {
            throw new RuntimeException(ex);
        }
    }
}